package com.tender.desensitization.factory.instance;

import java.util.Set;

public class SetProcessFactory implements TypeProcessFactory {

    private TypeProcessFactoryFacade factoryFacade;

    public SetProcessFactory(TypeProcessFactoryFacade factoryFacade) {
        this.factoryFacade = factoryFacade;
    }

    @Override
    public boolean supports(Class<?> clazz) {
        return Set.class.isAssignableFrom(clazz);
    }

    @Override
    public Object processType(Object instance) {
        if (null == instance) {
            return null;
        }
        Set set = (Set) instance;
        for (Object item : set) {
            if (null != item) {
                TypeProcessFactory processFactory = factoryFacade.getProcessFactory(item.getClass());
                if (null != processFactory) {
                    processFactory.processType(item);
                }
            }
        }
        return instance;
    }
}